package com.yaorange.jk.service.impl;

import com.yaorange.jk.dao.BaseDao;
import com.yaorange.jk.entity.Invoice;
import com.yaorange.jk.service.InvoiceService;
import com.yaorange.jk.utils.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional
@Service
public class InvoiceServiceImpl implements InvoiceService {
@Autowired
private BaseDao<Invoice,String> invoiceDao;

@Override
public Pagination findPage(Pagination page) {
return invoiceDao.pageByHql("from Invoice",page.getPageNo(),page.getPageSize(),null);
}

@Override
public List<Invoice> findAll() {
    return invoiceDao.getListByHQL("from Invoice");
    }

    @Override
    public void save(Invoice model) {
    	model.setState(0d);
    invoiceDao.save(model);
    }

    @Override
    public void deleteById(String id) {
    invoiceDao.deleteById(Invoice.class,id);
    }

    @Override
    public void update(Invoice model) {
    invoiceDao.update(model);
    }

    @Override
    public Invoice findById(String id) {
    return invoiceDao.get(Invoice.class,id);
    }

	@Override
	public void invoice(Invoice invoice) {
		invoice.setState(1d);
		invoiceDao.update(invoice);
		
	}

	@Override
	public Pagination findPage(Pagination page, double i) {
		return invoiceDao.pageByHql("from Invoice invoice where invoice.state=?",page.getPageNo(),page.getPageSize(),i);
	}

	@Override
	public void cancel(Invoice invoice) {
		invoice.setState(0d);
		invoiceDao.update(invoice);
	}
    }
